package publisherSubscriber;

import corbaEventService.EventServiceFactory;
import cosEventComm.PullSupplier;
import cosEventComm.PushConsumer;

public class Factory {
	EventServiceFactory esFactory;
	
	public Factory() throws Exception{
		esFactory = new EventServiceFactory();
	}
	
	public Factory(String host,String port) throws Exception{
		esFactory = new EventServiceFactory(host,port);
	}
	
	public Topic createTopic(String topicName) throws Exception{		
		return new Topic(topicName, esFactory.createEventChannel(topicName));
	}
	
	public Subscriber createSubscriber(String topicName,String subscriberName) throws Exception{
		PullSupplier ps = esFactory.createPullSupplier(topicName, subscriberName);
		esFactory.getEventChannel(topicName).for_suppliers().obtain_pull_consumer().connect_pull_supplier(ps);
		return new Subscriber(subscriberName, ps);
	}
	
	public Publisher createPublisher(String topicName,String publisherName) throws Exception{
		PushConsumer pc = esFactory.createPushConsumer(topicName, publisherName);
		esFactory.getEventChannel(topicName).for_consumers().obtain_push_supplier().connect_push_consumer(pc);
		return new Publisher(publisherName, esFactory.createPushConsumer(topicName,  publisherName));
		
	}

}
